/**
 * 构建操作列
 */
function optColumn(val,row,index)
{
	var optStr="";
	
	optStr+="<a href='javascript:void(0)' onclick='javascript:toDetail("+val+","+row.questionnaireId+","+row.autoSend+")' style='color:blue'><u>详细</u></a>";
	optStr+="&nbsp;";
	optStr+="<a href='javascript:void(0)' onclick='javascript:toDelete(\""+val+"\",\""+row.patientName+"\",\""+row.title+"\")' style='color:blue'><u>删除</u></a>";
	
	return optStr;
}

/**
 * 进入答卷明细
 */
function toDetail(answerId,questionnaireId,autoSend)
{
	var url="/pac/questionnaire/answer/detail?questionnaireId="+questionnaireId+"&answerId="+answerId;
	if((questionnaireId!="48")&&(questionnaireId!="49")&&(questionnaireId!="51")&&(questionnaireId!="52")&&(questionnaireId!="53")&&(questionnaireId!="54"))
	{
		var questionnaireType="1";
		if(autoSend=="0")
		{
			questionnaireType="0";
		}
		url="/pac/questionnaire/answer/view?questionnaireId="+questionnaireId+"&answerId="+answerId+"&goback=true&questionnaireType="+questionnaireType;
	}
	window.location.href=url;
}

/**
 * 删除答卷
 */
function toDelete(answerId,patientName,title)
{
	$.messager.confirm("提示", "是否删除["+patientName+"]的["+title+"]答卷？"+title, function(r){
		if (r){
			$.ajax({
				type: "get",
				url: "../questionnaire/answer/delete",
				data:{
					answerId:answerId
				},
				success: function(data){
					if(data.result==true)
					{
						$("#gridQuestionnaireAnswer").datagrid("load",{data:{random:function(){return Math.random();}}});
					}
					else
		            {
		            	$.messager.alert("提示",data.msg,"error");
		            }
				},
				error:function(err){
					$.messager.alert("提示",err.responseText,null,function(){
						window.location.href="../login/toLogin";
					});
				}
			});
		}
	});
}

/**
 * 条件查询答卷
 */
function searchQuestionnaireAnswer()
{
	var patientName=$("#txtPatientName").textbox("getValue");
	var answerDateStart=$("#txtAnswerDateStart").datebox("getValue");
	var answerDateEnd=$("#txtAnswerDateEnd").datebox("getValue");
	if(answerDateStart!='')
	{
		answerDateStart=answerDateStart+" 00:00:00";
	}
	if(answerDateEnd!='')
	{
		answerDateEnd=answerDateEnd+" 23:59:59";
	}
	
	$("#gridQuestionnaireAnswer").datagrid("load",{
		patientName:patientName,
		answerDateStart:answerDateStart,
		answerDateEnd:answerDateEnd
	});
}
